﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShevaEngine.Core.Modules.Materials
{
    /// <summary>
    /// Graphics material parameters manager.
    /// </summary>
    public class GraphicsMaterialParametersManager
    {
        /// <summary>Parameters.</summary>
        private List<GraphicsMaterialParametersList> Parameters;
        /// <summary>Parameters indexer.</summary>
        private Dictionary<GraphicsMaterialParametersList, UInt16> ParametersIndexer;

        /// <summary>
        /// Materil parameters for Id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public GraphicsMaterialParametersList this[UInt16 id] { get { return this.Parameters[(int)id]; } }

        /// <summary>
        /// Constructor.
        /// </summary>
        public GraphicsMaterialParametersManager()
        {
            this.Parameters = new List<GraphicsMaterialParametersList>();
            this.ParametersIndexer = new Dictionary<GraphicsMaterialParametersList, ushort>(
                new GraphicsMaterialParametersListEqualityComparer());
        }

        /// <summary>
        /// Method returns parameters ID.
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public UInt16 GetParametersID(GraphicsMaterialParametersList parameters)
        {
            if (!this.ParametersIndexer.ContainsKey(parameters))
            {
                this.ParametersIndexer.Add(parameters, (UInt16)this.Parameters.Count);

                this.Parameters.Add(parameters);

                return (UInt16)(this.Parameters.Count - 1);
            }

            return this.ParametersIndexer[parameters];
        }
    }
}
